<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/include/commonHeader::commonHeader('人员冲突列表')"></head>
<body class="gray-bg layer-blue">
<div class="wrapper wrapper-content animated fadeInRight full-container">
    <div class="row" id="container">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <div class="btn-group table-tool" id="exampleToolbar" role="group">
                    <input id="query_year" type="text" class="table-tool-btn pull-left"
                           placeholder="年份"/>
                    <input id="query_userName" type="text" class="table-tool-btn pull-left"
                           placeholder="姓名/首字母"/>

                    <button type="button" onclick="reload()" class="btn btn-outline btn-success "
                            data-toggle="tooltip" title="刷新">
                        <i class="fa fa-refresh" aria-hidden="true"></i>
                    </button>
                </div>
                <table id="exampleTable" data-classes="table table-hover table-condensed">
                </table>
            </div>
        </div>
    </div>
</div>

<script src="/plugins/layer/layer.js"></script>
<script type="text/javascript">
    //var p_edit = 'hidden';
    var p_edit = '';
</script>
<shiro:hasPermission name="crew:crewConflict:edit">
    <script type="text/javascript">
        p_edit = '';
    </script>
</shiro:hasPermission>

<!-- 自定义js -->
<script th:inline="javascript">
    var prefix = "/crewFlightHours";
    var dutyCode = "[[${dutyCode}]]".substr(1,1);

    $(function () {
        load();
    });
    function load() {
        var myDate = new Date();
        myDate.getFullYear(); //获取当前年份(2位)

        $('#query_year').val(myDate.getFullYear());
        $('#exampleTable').bootstrapTable(
            {
                method: 'post',
                url: prefix + "/list.do",
                //iconSize: 'outline',
                toolbar: '#exampleToolbar',
                striped:true,
                showRefresh:true,
                dataType:'json',
                locale:"zh-CN",
                pagination:true,//是否分页
                pageList:[10,30,50],//可选每页页数
                pageSize:10,//每页记录行数
                pageNumber:1,//初始化加载第一页
                sidePagination:'server',//分页方式
                contentType: "application/x-www-form-urlencoded",
                queryParams: function (params) {
                    return {
                        fullName: $("#query_userName").val(),
                        dutyCode: dutyCode,
                        year:$("#query_year").val(),
                        limit: params.limit,
                        offset: params.offset
                    };
                },
                onClickRow:function(row, $element){
                    $element.addClass('info').siblings().removeClass('info').end();
                },
                onDblClickRow: function (row, $element, field) {
                    view(row.id);
                },
                columns: [
                    {
                        field: 'idx',
                        formatter: orderFormatter,
                        title: '序号',
                        align: 'center',
                        width: '40'
                    },
                    {
                        field: 'deptName',
                        title: '部门'
                    },
                    {
                        field: 'fullName',
                        title: '人员'
                    },
                    {
                        field: 'scheduling',
                        title: '排班授权'
                    },
                    {
                        field: 'maxMonthHours',
                        title: '最大月飞'
                    },
                    {
                        field: 'maxYearHours',
                        title: '最大年飞'
                    },
                    {
                        field: 'usedYearHours',
                        title: '年已飞合计',
                        formatter: function (value, row, index) {
                            return value.toFixed(2);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '1月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(1,row);
                        },
                    },
                    {
                        field: 'usedMonthHours',
                        title: '2月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(2,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '3月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(3,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '4月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(4,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '5月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(5,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '6月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(6,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '7月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(7,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '8月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(8,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '9月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(9,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '10月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(10,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '11月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(11,row);
                        }
                    },
                    {
                        field: 'usedMonthHours',
                        title: '12月',
                        formatter: function (value, row, index) {
                            return getHoursOfMonth(12,row);
                        }
                    }]
            })
    }


    //刷新
    function reload() {
        $("#exampleTable").bootstrapTable('refresh');
    }

    function orderFormatter(value, row, index) {
        return index + 1;
    }

    function getHoursOfMonth(month,row){
        var values = row.usedMonthHours;
        if(values!=null && row.workcode != null){
            for(var i=0;i<values.length;i++){
                if(month == values[i].month%100){
                    return "<a class='check' style='cursor:pointer' onclick=check("+values[i].month+",'"+row.workcode+"','"+row.fullName+"')>"+(values[i].value/60).toFixed(2)+"</a>";
                }
            }
        }
    }
    function check(month,workcode,fullName){
        layer.open({
            type: 2,
            title: fullName+month+'飞行小时明细',
            shadeClose: false, // 点击遮罩关闭层
            area: ['90%', '90%'],
            content: prefix + '/toEditPage.do?workcode=' + workcode+'&month='+month,
        });
    }

</script>
</body>
</html>